package com.indexingsystem.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.Vo.IprulesVo;
import com.indexingsystem.boss.Vo.TreeQueryVo;
import com.indexingsystem.boss.admin.mapper.IprulesMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.Iprules;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.IIprulesService;

@Service
public class IprulesServiceImpl implements IIprulesService {

	@Resource
	private IprulesMapper iprulesMapper;

	@Override
	public int deleteByPrimaryKey(String ipRuleId) {
		return iprulesMapper.deleteByPrimaryKey(ipRuleId);
	}
	
	/**
	 * 获取最上级机构列表总数量.
	 * 
	 * @return
	 */
	@Override
	public Integer getFirstIpRulesCount() {
		return iprulesMapper.getFirstIpRulesCount();
	}
	
	/**
	 * 获取最上级机构列表.
	 * 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@Override
	public PagedResult<IprulesVo> getFirstIprulesList(TreeQueryVo treeQueryVo){
		Integer pageNo = treeQueryVo.getPageNumber() == null ? 1 : treeQueryVo.getPageNumber();
		Integer pageSize = treeQueryVo.getPageSize()== null ? 10 : treeQueryVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(iprulesMapper.getFirstIprulesList(treeQueryVo));
	}
	
	/**
	 * 获取ip规则总记录数.
	 * 
	 * @return
	 */
	@Override
	public Integer getIpRulesCount(TreeQueryVo treeQueryVo) {
		return iprulesMapper.getIpRulesCount(treeQueryVo);
	}

	@Override
	public int insertSelective(Iprules record) {
		return iprulesMapper.insertSelective(record);
	}

	@Override
	public IprulesVo selectByPrimaryKey(String ipRuleId) {
		return iprulesMapper.selectByPrimaryKey(ipRuleId);
	}

	@Override
	public int updateByPrimaryKeySelective(Iprules record) {
		return iprulesMapper.updateByPrimaryKeySelective(record);
	}
	
	/**
	 * 通过机构id和规则名称校验机构ip段是否重复.
	 * @param iprulesVo
	 * @return
	 */
	@Override
	public List<IprulesVo>  queryIprulesByInstitutionsId(String institutionsId){
		return iprulesMapper.queryIprulesByInstitutionsId(institutionsId);
	}

	@Override
	public PagedResult<IprulesVo> selectIprulesList(TreeQueryVo treeQueryVo) {
		Integer pageNo = treeQueryVo.getPageNumber() == null ? 1 : treeQueryVo.getPageNumber();
		Integer pageSize = treeQueryVo.getPageSize() == null ? 10 : treeQueryVo.getPageSize();
		// startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo, pageSize);
		return BeanUtils.toPagedResult(iprulesMapper.selectIprulesList(treeQueryVo));
	}

	@Override
	public Iprules selectByRuleName(String ruleName) {
		return iprulesMapper.selectByRuleName(ruleName);
	}

	@Override
	public int deleteIprulesByIdBatch(List<String> ipRuleIdList) {
		return iprulesMapper.deleteIprulesByIdBatch(ipRuleIdList);
	}

	@Override
	public Iprules selectByPrimaryIprulesId(String ipRuleId) {
		return iprulesMapper.selectByPrimaryIprulesId(ipRuleId);
	}
	
	
	/**
     * 通过机构id获取机构所属ip规则列表.
     * @param institutionsId
     * @return
     */
    @Override
    public List<Iprules> getIprulesList(String institutionsId){
        return iprulesMapper.getIprulesList(institutionsId);
    }
}